package com.csu.device.web;


import com.alibaba.fastjson.JSONArray;
import com.csu.device.service.BigScreenService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 大屏接口
 */
@Controller
@RequestMapping("/bigScreen")
public class BigScreenController {


    @Autowired
    private BigScreenService bigScreenService;

    private Logger logger = LoggerFactory.getLogger(BigScreenController.class);

    /**
     * 获取老人最新体征记录
     * @param jsonArray
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "findTomatic", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    @ResponseBody
    public List<Map<String,Object>> findTomatic(@RequestBody JSONArray jsonArray) throws Exception {

        Map<String,Object> map=new HashMap<>();
        map.put("userIds",jsonArray);
        return bigScreenService.findTomatic(map);
    }


    /**
     * 查询一个场景所有设备
     * @param sceneId
     * @return
     */
    @CrossOrigin(origins="*")
    @ResponseBody
    @RequestMapping("/findDevice/{sceneId}")
    public List<Map<String,Object>> findDevice(@PathVariable("sceneId") String sceneId) {
        Map<String,Object> map=new HashMap<>();
        map.put("sceneId",sceneId);
        return bigScreenService.findDevice(map);
    }

    /**
     * 查询一个场景所有设备
     * @param sceneId
     * @return
     */
    @CrossOrigin(origins="*")
    @ResponseBody
    @RequestMapping("/findBehavior/{sceneId}/{limit}")
    public List<Map<String,Object>> findBehavior(@PathVariable("sceneId") String sceneId,@PathVariable("limit") Integer limit) {
        Map<String,Object> map=new HashMap<>();
        map.put("sceneId",sceneId);
        map.put("limt",limit);
        map.put("anomalies","0");
        return bigScreenService.findBehavior(map);
    }

    /**
     * 查询房间的异常
     * @param sceneId
     * @return
     */
    @CrossOrigin(origins="*")
    @ResponseBody
    @RequestMapping("/findBehaviorError/{sceneId}/{limit}")
    public List<Map<String,Object>> findBehaviorError(@PathVariable("sceneId") String sceneId,@PathVariable("limit") Integer limit) {
        Map<String,Object> map=new HashMap<>();
        map.put("sceneId",sceneId);
        map.put("limt",limit);
        map.put("anomalies","1");
        return bigScreenService.findBehavior(map);
    }


    /**
     * 查看一周以内设备使用次数
     * @param sceneId
     * @return
     */
    @CrossOrigin(origins="*")
    @ResponseBody
    @RequestMapping("/findAllBehaviorGroupByScene/{sceneId}")
    public Map<String, List<Map<String, Object>>> findAllBehaviorGroupByScene(@PathVariable("sceneId") String sceneId) {
        Map<String,Object> map=new HashMap<>();
        map.put("sceneId",sceneId);
        return bigScreenService.findAllBehaviorGroupByScene(map);
    }


    /**
     * 陈海宝获取所有房间接口
     * @return
     */
    @CrossOrigin(origins="*")
    @ResponseBody
    @RequestMapping("/findAllRoom")
    public List<Map<String,Object>> findAllRoom() {
        Map<String,Object> map=new HashMap<>();
        return bigScreenService.findAllRoom(map);
    }
}
